from joblib import load
import numpy as np

class ClassFication(object):  
    def __init__(self):
        self.knn = load("knn_model.joblib")
        self.label_encoder = load("label_encoder.joblib")
        self.scaler = load("scaler.joblib")
      
        
    def get_predicter_category(self, X):  
        features_order = ['eps', 'total_revenue_ps', 'undist_profit_ps', 'gross_margin', 'fcff', 'fcfe', 'tangible_asset', 'bps', 'grossprofit_margin', 'npta']
        new_value = np.array([X[feature] for feature in features_order])
        
        new_scaled = self.scaler.transform([new_value]) 
        
        predicted_label = self.knn.predict(new_scaled)
        
        predicted_category = self.label_encoder.inverse_transform(predicted_label)
        return predicted_category[0]
        
        
if __name__ == '__main__':
    c1 = ClassFication()
    X = {
        'eps': 0.5,
        'total_revenue_ps': 100,
        'undist_profit_ps': 50,
        'gross_margin': 0.6,
        'fcff': 1000,
        'fcfe': 800,
        'tangible_asset': 5000,
        'bps': 10,
        'grossprofit_margin': 0.5,
        'npta': 0.8,
    }
    category = c1.get_predicter_category(X)
    print(category)